<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search :config='searchConfig' @search='search' @getHeight='getHeight'/>
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config='tableToolbar'
        :checkbox-config='checkboxConfig'
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click='handleAdd' v-has="'terminal:add'" type='primary'>新增</a-button>
            <a-button type="primary" @click="startorstop(1)">启用</a-button>
            <a-button type="primary" @click="startorstop(0)">停用</a-button>
            <a-button v-has="'terminal:delete'" @click='getDelete'>删除</a-button>
          </div>
        </template>

        <template #avatarslot='{ row }'>
          <viewer :images='[row.avatar]'>
            <a-avatar shape='square' size='small' :src='row.avatar' icon='user'/>
          </viewer>
        </template>
        <template #status="{ row,rowIndex }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.terminalCode }}</a>
        </template>
        <template #isLeader='{ row }'>
          {{ row.isLeader == 0 ? '是' : '否' }}
        </template>
        <div slot='isActiveStatus' slot-scope='text,recode'>
          {{ text|isActiveStatus }}
        </div>
        <div slot='filterTerminalType' slot-scope='text,recode'>
          {{ text|filterTerminalType }}
        </div>

        <template #action='{ row:record }'>
          <a v-has="'terminal:update'" @click='handleEdit(record)'>编辑</a>
        </template>

        <template #pager>
          <vxe-pager :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
                     :currentPage.sync='ipagination.current' :page-size.sync='ipagination.pageSize'
                     :total='ipagination.total'
                     :pageSizes='ipagination.pageSizeOptions' @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <pic-factory-modal ref="modalForm" @ok="modalFormOk"></pic-factory-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import PicFactoryModal from './modules/PicFactoryModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction } from '@/api/manage'
import ARow from 'ant-design-vue/es/grid/Row'
import ARangePicker from 'ant-design-vue/es/date-picker/RangePicker'

export default {
  name: 'PicFactoryList',
  mixins: [PageListMixin],
  components: {
    ARangePicker,
    ARow,
    PicFactoryModal
  },
  data () {
    return {
      description: '海报宣传',
      searchConfig: [
        {
          type: 'j-select',
          dictCode: 'user_Type',
          name: 'userType',
          placeholder: '用户类型'
        },
        {
          type: 'j-select',
          dictCode: 'term_status',
          name: 'status',
          placeholder: '使用状态'
        },
        {
          type: 'date',
          name: 'startTime',
          placeholder: '开始时间'
        },
        {
          type: 'date',
          name: 'endTime',
          placeholder: '结束时间'
        },
      ],
      // 表头
      columns: [
        {
          type: 'checkbox',
          minWidth: 60,
          fixed: 'left'
        },
        {
          title: '标题',
          minWidth: 80,
          field: 'title',
        },
        {
          title: '海报类型',
          minWidth: 80,
          field: 'dataType'
        },
        {
          title: '资料类型',
          minWidth: 80,
          field: 'materialType'
        },
        {
          title: '组织',
          minWidth: 80,
          field: 'orgName'
        },
        // {
        //   title: '用户',
        //   minWidth: 80,
        //   field: 'appointorName'
        // },
        {
          title: '开始时间',
          minWidth: 80,
          field: 'startTime'
        },
        {
          title: '结束时间',
          minWidth: 80,
          field: 'endTime'
        },

        {
          title: '内容',
          minWidth: 80,
          field: 'remarks'
        },
        // {
        //   title: '是否删除',
        //   minWidth: 80,
        //   field: 'deleteStatus',
        //   customRender: function (text) {
        //     if (text === '009') {
        //       return '否';
        //     } else {
        //       return '是';
        //     }
        //   }
        // },
        {
          title: '创建人姓名',
          minWidth: 100,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime'
        },
        {
          title: '更新人姓名',
          minWidth: 100,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 80,
          field: 'updateTime'
        },
        {
          title: '状态',
          minWidth: 120,
          field: 'status',
          slots: { default: 'status' }
        },
        {
          title: '操作',
          fixed: 'right',
          field: 'action',
          minWidth: 80,
          slots: {default: 'action'}
        }
      ],
      url: {
        list: window._CONFIG['domianSfaURL']+ "/picfactory/findPageList",
        detail: window._CONFIG['domianSfaURL'] + '/picfactory/getInfo',
        deleteBatch: window._CONFIG['domianSfaURL']+ "/picfactory/deleteBatch",
        startOrStopUrl: window._CONFIG['domianSfaURL']+ "/picfactory/startOrStopBatch"
      }
    }
  },
  methods: {
    startorstop: function(status) {
      if (!this.url.startOrStopUrl) {
        this.$message.error("请设置url启用停用!")
        return;
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');

      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        that.loading = true;
        getAction(this.url.startOrStopUrl, {ids: ids, status: status}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
          that.loading = false;
        });
      }
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>